import com.mosesSupposes.fuse.*;
import com.Lithyem.XMLLoader;
import com.Lithyem.NSGS.Profiles.xmlparser;
import com.Lithyem.Data;
import com.Lithyem.LoaderQueue;
import com.Lithyem.CustomMenu;
import com.Lithyem.ColorTools;

class com.Lithyem.NSGS.Profiles.AppShell extends Object{
	
	var textscreens_mc:MovieClip;
	var imagemanager_mc:MovieClip;
	var gradientblock_mc:MovieClip;
	var translucentblocks_mc:MovieClip;
	
	var palettes:Object = {student:0xff3c22, alumni:0xf8cc45, faculty:0xf58039};
	var variants:Object = {light:"#888888,#bdbdbd,#000000", dark:"#242424,#CCCCCC,#ffffff"};
	
	
	var _xml:XML;
	var LiMenu:com.Lithyem.CustomMenu;
	var DataObject:com.Lithyem.Data;
	var timeline:Object;
	
	var xloader:com.Lithyem.XMLLoader;
	var xparser:com.Lithyem.NSGS.Profiles.xmlparser;
	
	
	function AppShell(tl:Object){
		timeline = tl;
		DataObject = new com.Lithyem.Data();
		LiMenu = new com.Lithyem.CustomMenu();
	}
	
	function init():Void{
		xloader = new com.Lithyem.XMLLoader();
		xloader.addEventListener("onFileLoad", this);
		
		if(!_root.xmlfile){
			xloader.loadFile('xml/student.xml');
		}else{
			xloader.loadFile(_root.xmlfile);
		}
		
	}
	
	function onFileLoad(obj:Object):Void{
		xparser = new com.Lithyem.NSGS.Profiles.xmlparser(DataObject);
		xparser.addEventListener("onXMLParsed", this);
		xparser.parseData(obj.data);
	}
	
	function onXMLParsed():Void{
		
		var sets = DataObject.getData('sets');
		var images = DataObject.getData('images');
		
		
		var _variant = DataObject.getData('variant');
		var variant = variants[_variant];
		
		var intro_text = DataObject.getData('intro_text');
		_root.intro_text = intro_text;
		
		// Gradient Block
		var ss = variant.split(',');
		var s = com.Lithyem.ColorTools.getHexFromString(ss[0]);
		var e = com.Lithyem.ColorTools.getHexFromString(ss[1]);	
		timeline.gradientblock_mc.init(s,e);
		
		
		var tc = com.Lithyem.ColorTools.getHexFromString(ss[2]);	
		timeline.textscreens_mc.init(sets,tc,this);
		
		var c_obj = new Color(timeline.play_btn);
		c_obj.setRGB(tc);
		
		// Trans Block
		var palette = DataObject.getData('palette');
		var c = palettes[palette];
		timeline.translucentblocks_mc.init(c);
		
		// Image Managers
		timeline.imagemanager_mc.init(images,this);
		
		
		
	}
	
	
	
	
	
	function beginAll():Void{
		//timeline.play_btn._visible = false;
		
		var f = new Fuse(
			{target:timeline.play_btn, alpha:0, seconds:.3, ease:'easeInQuad'},
			{target:timeline.play_btn, visible:false}
		);
		f.start();
		
		timeline.imagemanager_mc.nextImage();
	}
	
	function onPresentationComplete():Void{
		timeline.imagemanager_mc.reset();
		timeline.translucentblocks_mc.unshuffle();
		timeline.textscreens_mc.reset();
		
		//timeline.play_btn._visible = true;
		var f = new Fuse(
			{target:timeline.play_btn, visible:true},
			{target:timeline.play_btn, alpha:100, seconds:.3, ease:'easeInQuad'}
		);
		f.start();
	}
	
	function slideShowReady():Void{
		timeline.play_btn._visible = true;
		
	}
	
	function onBeginFadeInClip(i:Number):Void{
		
		timeline.translucentblocks_mc.shuffle();
		
		// pass this index to the text screen controller.
		
		
		var screens = new Array();
		screens[0] = "text 1";
		
		var image_to_screens:Array = new Array();
		image_to_screens[0] = 0;
		image_to_screens[1] = 0;
		image_to_screens[2] = 0;
		
		image_to_screens[3] = 1;
		
		
		var index = image_to_screens[i];
		
		
		// 
		timeline.textscreens_mc.showScreenByIndex(i);
	}
	
	/*
	function onTextBlock():Void{
		timeline.translucentblocks_mc.shuffle();
	}
	*/

}